package p.lodz.pl.poid.zad2.controller;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Slider;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javax.imageio.ImageIO;
import p.lodz.pl.poid.zad2.fourier.FourierProcessor;

/**
 * FXML Controller class
 *
 * @author janiu
 */
public class PhasePanelController implements Initializable {
    
    @FXML
    private Slider horizontally;
    
    @FXML
    private Slider vertically;

    private ImageView resultImage;
    private Image image;
    private BufferedImage bufferedImage;
    
    
    @Override
    public void initialize(URL url, ResourceBundle rb) {
    }    

    @FXML
    private void moveHorizontally(MouseEvent event) {
        Double L = vertically.getValue();
        Double K = horizontally.getValue();
        FourierProcessor processor = new FourierProcessor();
        BufferedImage bufferedImage = processor.phaseTransform(this.bufferedImage, L, K);
        Image image = Image.impl_fromExternalImage(bufferedImage);
        resultImage.setImage(image);
    }
    
    @FXML
    private void moveVertically(MouseEvent event) throws IOException {
        Double L = vertically.getValue();
        Double K = horizontally.getValue();
        FourierProcessor processor = new FourierProcessor();
        BufferedImage bufferedImage = processor.phaseTransform(this.bufferedImage, L, K);
        ImageIO.write(bufferedImage, "jpg", new File("qwertyu.jpg"));
        Image image = Image.impl_fromExternalImage(bufferedImage);
        resultImage.setImage(image);
    }

    public void setResultImage(ImageView resultImage) {
        this.resultImage = resultImage;
    }

    public void setImage(Image image) {
        this.image = image;
    }

    public void setBufferedImage(BufferedImage bufferedImage) {
        this.bufferedImage = bufferedImage;
    }
    
}
